using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace FinlogiK.FxCop.Statistics.Windows
{
	internal partial class ListForm : Form
	{
		#region Constructors

		internal ListForm()
		{
			InitializeComponent();
		}

		#endregion

		#region Properties

		protected DataGridView Grid
		{
			get
			{
				return this.mainGrid;
			}
		}

		#endregion

		#region Methods

		protected void SetGridBindingSource(object bindingSource)
		{
			this.gridBindingSource.DataSource = bindingSource;
		}

		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad(e);
			if (!this.DesignMode) this.mainGrid.Columns.AddRange(this.GetGridColumns());
		}

		protected virtual DataGridViewColumn[] GetGridColumns()
		{
			throw new NotSupportedException();
		}

		protected virtual void SaveData()
		{
			throw new NotSupportedException();
		}

		protected virtual DataGridViewColumn MakeTextBoxColumn(string headerText, string dataPropertyName)
		{
			return this.MakeTextBoxColumn(headerText, dataPropertyName, false);
		}

		protected virtual DataGridViewColumn MakeTextBoxColumn(string headerText, string dataPropertyName, bool frozen)
		{
			DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();
			this.PrepareGridColumn(column, headerText, dataPropertyName, frozen);

			return column;
		}
		
		protected virtual DataGridViewColumn MakeCheckBoxColumn(string headerText, string dataPropertyName)
		{
			return this.MakeCheckBoxColumn(headerText, dataPropertyName, false);
		}

		protected virtual DataGridViewColumn MakeCheckBoxColumn(string headerText, string dataPropertyName, bool frozen)
		{
			DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn();
			column.ThreeState = false;

			this.PrepareGridColumn(column, headerText, dataPropertyName, frozen);

			return column;
		}

		protected virtual DataGridViewColumn MakeButtonColumn(string headerText, string buttonText)
		{
			DataGridViewButtonColumn column = new DataGridViewButtonColumn();
			column.Text = buttonText;
			column.UseColumnTextForButtonValue = true;

			this.PrepareGridColumn(column, headerText, null, false);

			return column;
		}

		protected virtual void PrepareGridColumn(DataGridViewColumn column, string headerText, string dataPropertyName, bool frozen)
		{
			column.HeaderText = headerText;
			column.DataPropertyName = dataPropertyName;
			column.Frozen = frozen;
		}

		private void okButton_Click(object sender, EventArgs e)
		{
			this.SaveData();
			this.Close();
		}

		private void cancelButton_Click(object sender, EventArgs e)
		{
			this.Close();
		}

		protected virtual void MainGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
		{
		}

		protected DataGridViewRow GetGridRow(int rowIndex)
		{
			return this.mainGrid.Rows[rowIndex];
		}

		#endregion
	}
}